package com.guigu.buy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.buy.pojo.Customer;
import com.guigu.buy.mapper.CustomerMapper;
import com.guigu.buy.pojo.Order;
import com.guigu.buy.service.ICustomerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.buy.utils.PageUtils;
import com.guigu.buy.vo.CustomerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author com.guigu
 * @since 2024-05-15
 */
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements ICustomerService {
    @Autowired
    CustomerMapper customerMapper;

    @Override
    public List<Order> selectCustomer(Customer customer) {
        return customerMapper.selectCustomer(customer);
    }

    @Override
    public Customer selectLogin(String userAccount, String userPassword) {
        return customerMapper.selectLogin(userAccount, userPassword);
    }

    @Override
    public Customer getById(Integer id) {
        return customerMapper.getById(id);
    }

    @Override
    public int updateUserInfo(Customer customer) {
        return customerMapper.updateUserInfo(customer);
    }

    @Override
    public PageUtils<Customer> Alllist(int pageNo, int pageSize, CustomerVo vo) {
        QueryWrapper<Customer> wrapper = new QueryWrapper<>();

        if (vo != null) {
            if (vo.getUserAccount() != null) {
                wrapper.eq("userAccount", vo.getUserAccount());
            }
        }

        PageHelper.startPage(pageNo, pageSize);
        List<Customer> list = this.list(wrapper);
        PageInfo<Customer> pageInfo = new PageInfo<>(list);
        PageUtils<Customer> pageUtils = new PageUtils<>();
        pageUtils.setRows(pageInfo.getList());
        pageUtils.setTotal(pageInfo.getTotal());
        return pageUtils;
    }
}
